﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace 学生成绩查询及选课系统.teacher
{
    public partial class addStudetnScore : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string stuno = DropDownList1.SelectedValue.ToString();
            string cno = DropDownList2.SelectedValue.ToString();
            string score = TextBox1.Text;
            if (string.IsNullOrEmpty(stuno) || string.IsNullOrEmpty(cno) || string.IsNullOrEmpty(score))
            {
                Label1.Text = "请输入完整信息";
                return;
            }
            double flag = -1;
            if (double.TryParse(score, out flag))
            {
                if (flag < 0 || flag > 100)
                {
                    Label1.Text = "请输入0-100之间的分值！";
                    return;
                }
            }
            else
            {
                Label1.Text = "请输入0-100之间的分值！";
                return;
            }

            string sql2 = "select count(*) from grade where stuno=@stuno and cno=@cno ";
            SqlParameter[] sqlarray2 = { new SqlParameter("@stuno",stuno),
                                              new SqlParameter("@cno",cno)};
            object res2 = DBAccess.GetOne(sql2, sqlarray2);
            if ((int)res2 != 0)
            {
                Label1.Text = "该学生的课程已有成绩信息!";
                return;
            }

            string sql = "insert into grade(stuno,cno,score) values(@stuno,@cno,@score)";
            SqlParameter[] sqlarray = { new SqlParameter("@stuno",stuno),
                                              new SqlParameter("@cno",cno),new SqlParameter("@score",score)};
            int res = DBAccess.GetState(sql, sqlarray);
            if (res != 0)
            {
                Label1.Text = "成功录入学生成绩!";
            }
            else
            {
                Label1.Text = "录入失败!";
                return;
            }
        }
    }
}